<project name="Explica" default="dist" basedir=".">

	<target name="setEnvironment">
		<!-- The default deploy environment will be DEVELOPMENT -->
	        <condition property="DEPLOY_ENVIRONMENT" value="dev">
			<and>
				<isset property="environment"/>
				<equals arg1="${environment}" arg2="dev" casesensitive="false" trim="true"/>
			</and>
		</condition>

		<condition property="DEPLOY_ENVIRONMENT" value="pro">
			<and>
				<isset property="environment"/>
				<equals arg1="${environment}" arg2="pro" casesensitive="false" trim="true"/>
			</and>
		</condition>

		<condition property="DEPLOY_ENVIRONMENT" else="dev">
			<and>
				<isset property="environment"/>
				<equals arg1="${environment}" arg2="dev" casesensitive="false" trim="true"/>
				<equals arg1="${environment}" arg2="pro" casesensitive="false" trim="true"/>
			</and>
		</condition>
	</target>

	<target name="loadEnvironmentProperties" depends="setEnvironment">
		<taskdef resource="net/sf/antcontrib/antlib.xml"/>


		<if>
			<equals arg1="${DEPLOY_ENVIRONMENT}" arg2="dev" />
			<then>
				<echo message="Loading properties for Development environment..." />
				<property file="DevelopmentConfig.properties"/>
			</then>
			<else>
				<echo message="Loading properties for Production environment..." />
				<property file="ProductionConfig.properties"/>
			</else>
		</if>
	</target>
	
	<target name="init" depends="loadEnvironmentProperties">

        
		<tstamp>
			<format property="COMPLETE_DATE" pattern="dd-MM-yyyy hh:mm" locale="es"/>
		</tstamp>
		
		<ant antfile="versioningPolicy.xml" target="updateVersion"/>
		<property file="${pathVersionStore}/${versionStoreFile}"/>
		<property name="version" value="${explica.principal.version}.${explica.secondary.version}"/>

		<mkdir dir="${dist.dir}"/>
	  	<mkdir dir="${dist.dir}/${server.dir}"/>
  		<mkdir dir="${dist.dir}/${server.dir}/${modules.dir}"/>
  		<mkdir dir="${dist.dir}/${server.dir}/${resources.dir}"/>
		<mkdir dir="${dist.dir}/${server.dir}/${logs.dir}"/>
		<mkdir dir="${dist.dir}/${server.dir}/${externalLib.dir}"/>
  		<mkdir dir="${dist.dir}/${client.dir}"/>
	  	<mkdir dir="${dist.dir}/${client.dir}/${modules.dir}"/>
  		<mkdir dir="${dist.dir}/${client.dir}/${resources.dir}"/>
		<mkdir dir="${dist.dir}/${client.dir}/${logs.dir}"/>
		<mkdir dir="${dist.dir}/${client.dir}/${externalLib.dir}"/>
	</target>

	<target name="clean" depends="loadEnvironmentProperties">
		<delete includeEmptyDirs="true">
			<fileset dir="${dist.dir}">
				<include name="**/*"/>
				<exclude name="**/CVS/*"/>
				<exclude name="**/resources/appImages/*"/>
			</fileset>
		</delete>
	</target>

	<target name="explicaCore" depends="clean, init">
		<ant antfile="ExplicaCore_jar.xml" target="dist"/>
	</target>

	<target name="explicaWarehouse" depends="clean, init">
		<ant antfile="ExplicaWarehouse_jar.xml" target="dist"/>
	</target>
	
	<target name="explicaClients" depends="clean, init">
		<ant antfile="ExplicaClients_jar.xml" target="dist"/>
	</target>

	<target name="compile" depends="clean, init">
		<echo message="Compiling Explica application for the environment ${DEPLOY_ENVIRONMENT}..."/>
		<ant antfile="ExplicaCore_jar.xml" target="compile"/>
		<ant antfile="ExplicaWarehouse_jar.xml" target="compile"/>
		<ant antfile="ExplicaClients_jar.xml" target="compile"/>
	</target>

	<target name="dist" depends="clean, init, explicaCore, explicaWarehouse, explicaClients">
		<echo message="Building Explica application for the environment ${DEPLOY_ENVIRONMENT}..."/>

		<copy todir="${dist.dir}/${server.dir}/${resources.dir}" includeemptydirs="false">
			<fileset dir="${src.dir}/org/ceteca/explica/resources" includes="**/*"/>
		</copy>
		<copy todir="${dist.dir}/${client.dir}/${resources.dir}" includeemptydirs="false">
			<fileset dir="${src.dir}/org/ceteca/explica/resources" includes="resources, **/img/logo.png"/>
		</copy>

		<ant antfile="Aplicacion_jar.xml" target="dist"/>
	</target>

	<target name="doc" depends="init">
		<ant antfile="javadocExplica.xml" target="doc"/>
	</target>

	<target name="all" depends="dist, doc"/>
</project>
